<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>编辑合同</title>
    <link rel="stylesheet" href="../../lib/layui/layui/css/layui.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <script type="text/javascript" src="../../js/news/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui/lay/dest/layui.all.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/layui/layui/layui.js"></script>
    <style>
        * {
            font-family: "Microsoft Yahei" !important;
        }

        nav button {
            margin-left: 5px;
            padding: .25rem .5rem;
            font-size: .875rem;
            border-radius: .2rem;
            float: right !important;
            margin-top: 10px
        }

        nav div {
            float: left !important;
            margin: 15px;
        }

        nav {
            height: 50px;
            border-bottom: 1px solid #cfdbe2;
            background-color: #fafbfc;
            border-radius: 0;
        }

        .layui-tab-title {
            border-bottom: 1px solid #cfdbe2;
            background-color: #fafbfc;
        }

        .layui-tab {
            margin: 0;
        }

        .content {
            height: 509px;
            overflow: auto;
            margin: 14px;
            padding: 14px;
            background: #fff;
        }

        .layui-tab-content {
            background-color: #F5F7FA;
        }

        .search {
            display: inline;
            margin-bottom: 1px;
            padding-top: 6px;
            padding-bottom: 6px;
            width: 190px;
            border: 0;
        }

        .layui-form-label {
            width: 150px;
        }

        .spanText {
            margin-top: 25px;
            display: inline-block;
            margin-right: 5px;
            background: #e8e8e8;
            color: #333;
            border-radius: 30px;
            line-height: 27px;
            padding-left: 20px;
            padding-right: 20px;
            position: relative;
            max-width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .layui-form-select {
            overflow: visible;
        }

        .relative {
            background-color: #fff;
            border: 2px solid #ececec;
            border-radius: 6px;
            height: 140px;
            width: 140px;
            overflow: visible;
        }

        .layui-table > tbody div[class*='0-11'] {
            overflow: visible !important;
        }

        #addTableDiv .layui-table-cell {
            height: auto;
            overflow: visible;
        }
        #addTableDiv .laytable-cell-1-0-6,.laytable-cell-1-0-7{
            overflow: hidden;
        }
        #addTableDiv .laytable-cell-1-0-7{
            overflow: hidden;
        }

        #orderTableDiv .layui-table-cell {
            height: auto;
            overflow: visible !important;
        }

        td .layui-form-select {
            margin-top: -10px;
        }

        body {
            overflow-y: hidden;
        }
        .addBtn{
            background: #f2f2f2;
            margin: 0px 15px;
            padding: 10px 0;
        }
        .layui-card-body {
            padding: 0 15px;
            margin-top: -10px;
        }
        .layui-inline b {
            color: red;
        }
        .bg{
            background-color: #99FFFF;
        }
        .newNum{
            cursor: not-allowed;
        }
        .contrac{
            cursor: not-allowed;
        }
    </style>
</head>
<body>
<nav>
    <div>编辑合同</div>
    <button type="button" class="layui-btn layui-btn-primary layui-btn-sm return" style="margin-right: 30px" contractId="">
        返回
    </button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm save"  contractId="">
        保存
    </button>
</nav>
<div>
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
            <li>合同正文</li>
            <li>子合同</li>
            <li>结算情况</li>
            <li>订单</li>
            <li>相关流程</li>
            <li>提醒计划</li>
            <li>附件</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="content">
                    <form class="layui-form" id="ajaxforms">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">合同编号</label><b>*</b>
                                <div class="layui-inline"  style="width:352px;">
                                    <input type="text" name="contractNo" class="layui-input required layui-disabled contractNo"  disabled>
                                </div>
                                <button type="button" class="layui-btn layui-btn-sm newNum">已取号</button>
                                <button type="button" class="layui-btn layui-btn-sm contrac" name="contractNo">新取号</button>
                            </div>
                            <div class="layui-inline" style="margin-left: 85px;">
                                <label class="layui-form-label" style="width: 76px;">合同标题</label><b>*</b>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" class="layui-input required">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item" style="overflow: visible;">
                            <div class="layui-inline" style="overflow: visible;">
                                <label class="layui-form-label">合同类型</label><b>*</b>
                                <div class="layui-input-inline layui-form" style="overflow: visible;"
                                     lay-filter="mySelect">
                                    <select id="contractType" lay-verify="required" lay-filter="warehouse" class="required">

                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline" style="margin-left: -8px;">
                                <label class="layui-form-label">合同种类</label>
                                <div class="layui-input-inline">
                                    <div class="layui-input-inline layui-form" style="overflow: visible" lay-filter="mySelect">
                                        <select  lay-verify="required" lay-filter="contract_type" name="contract_type" id="contract_type">
                                        </select>
                                    </div>
                                </div>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">合同对象</label><b>*</b>
                                <div class="layui-input-inline">
                                    <input type="text" name="targetName" class="layui-input required">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">主合同</label>
                                <div name="Mastercontract" class="layui-input-inline;border-bottom: 1px solid #ccc" style="display:inline">
                                    <input type="text" style="border-bottom: 1px solid #ccc;" readonly class="search parent" placeholder="搜索"/>
                                    <span style="padding: 5px;color: #999;cursor: pointer;margin-left:-26px">
                                        <i class="layui-icon layui-icon-username master"></i></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">合同金额</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="money" class="layui-input" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">金额大写</label>
                                <div class="layui-input-inline">
                                    <input style="border: none" type="text" name="moneyCp" class="layui-input" disabled>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aUser" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bUser" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方地址</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aAddress" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方地址</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bAddress" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方联系人</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aLinkman" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方联系人</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bLinkman" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方电话</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aPhone" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方电话</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bPhone" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方签字</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aSign" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方签字</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bSign" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">甲方签字日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="aSignTime" id="aSignTime" lay-verify="date"
                                           placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">乙方签字日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bSignTime" id="bSignTime" lay-verify="date"
                                           placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">授权日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="date_comment" id="authorization" lay-verify="date"
                                           placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="margin-right: 8px;">授权代表</label>
                                <div class="layui-input-inline"  style="margin-left: -9px">
                                    <input type="text" name="authorized_representative"  class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">合同工期开始日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="duration_startdate" id="begins" lay-verify="date"
                                           placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">合同工期结束日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="duration_enddate" id="endtime" lay-verify="date"
                                           placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">对方单位</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="othersideunit" value="1" title="甲方" class="other">
                                    <input type="radio" name="othersideunit" value="2" title="乙方" class="other">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" >执行单位</label>
                                <div class="layui-input-inline">
                                    <div class="layui-input-inline layui-form" style="overflow: visible;" lay-filter="mySelect">
                                        <select  lay-verify="required" lay-filter="executive_unit" name="executive_unit" id="executive_unit" >
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <div class="layui-inline">
                                    <label class="layui-form-label">所属部门</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="rescueUser" dept_id=""  class="layui-input">
                                    </div>
                                    <a href="javascript:;" style="color:#1E9FFF" class="addExecute">添加</a>
                                    <a href="javascript:;" style="color:#1E9FFF" class="clearExecute">清空</a>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 90px;">备注</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="remarks" lay-verify="remarks" autocomplete="off"
                                               placeholder="请输入标题" class="layui-input">
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">风险评估</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="risk_assessment" value="0" title="否">
                                    <input type="radio" name="risk_assessment" value="1" title="是">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label"> 合同评审</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="contract_approval" value="0" title="否">
                                    <input type="radio" name="contract_approval" value="1" title="是">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">跟进人</label>
                                <div class="layui-input-block" id="userId">
                                    <%--<input type="text" name="userId" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">--%>
                                </div>
                            </div>
                            <div class="layui-inline" style="float: right;margin-right: 209px;">
                                <label class="layui-form-label">合同履行地点</label>
                                <div class="layui-input-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" name="do_address" class="layui-input">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content">
                        <textarea id="texPart" style="display: none;"></textarea>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content" id="local">
                        <span></span>
                        <div style="display: inline-block;border-bottom: 1px solid #ccc;" class="local">
                            <input type="text" class="search" readonly placeholder="搜索"/>
                            <span style="padding: 5px;color: #999;cursor: pointer;">
                                    <i class="layui-icon layui-icon-username localAet"></i>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content">
                        <div class="layui-card">
                            <div class="addBtn">
                                <button data-type="0" style="margin-left: 15px" type="button" id="addButton"
                                        class="layui-btn layui-btn-sm" lay-event="add"/>
                                添加
                            </div>
                            <div id="addTableDiv" class="layui-card-body">
                                <table class="layui-hide" id="settlementOf" lay-filter="settlementOf"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content">
                        <div class="addBtn">
                            <div data-type="0" style="margin-left: 15px" id="orderButton" class="layui-btn layui-btn-sm"
                                 lay-event="add">添加
                            </div>
                        </div>
                        <div id="orderTableDiv" class="layui-card-body">
                            <table class="layui-hide" id="order" lay-filter="order"></table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content" id="flow" runId="" conTractId="" runName="">
                        <span></span>
                        <div style="display: inline-block;border-bottom: 1px solid #ccc;" class="flow">
                            <input type="text" class="search" readonly placeholder="搜索"/>
                            <span style="padding: 5px;color: #999;cursor: pointer;">
                                    <i class="layui-icon layui-icon-search flowAet"></i>
                                </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content">
                        <div class="addBtn">
                            <div data-type="0" style="margin-left: 15px" id="planButton" class="layui-btn layui-btn-sm"
                                 lay-event="add">添加
                            </div>
                        </div>
                        <div id="planTableDiv" class="layui-card-body">
                            <table class="layui-hide" id="plan" lay-filter="plan"></table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-tab-item layui-show">
                    <div class="content">
                        <form class="layui-form" action="">
                            <button type="button" class="layui-btn layui-btn-normal" id="test3"><i
                                    class="layui-icon"></i>上传文件
                            </button>
                        </form>
                        <div style="margin: 20px 0;display: none">
                            <%--<span class="num"><i class="layui-icon layui-icon-link"></i> 1个附件</span>--%>
                            <%-----%>
                            <%--<span style="color:#03a9f4;cursor:pointer" class="everything">下载全部</span>--%>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%--</form>--%>
    <script type="text/html" id="settlementOfDel">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del2">删除</a>
    </script>
    <script type="text/html" id="orderDel">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del2">删除</a>
    </script>
    <script type="text/html" id="planDel">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del2">删除</a>
    </script>
</body>
<script type="application/javascript">
    $('.layui-input-inline').width($(document.body).width() / 3 - 70);
    $('.layui-input-inline select').width($(document.body).width() / 3);
    $('.content').height($(window).height() - 130);

    var form,layer,laydate,layedit,table,upload,element; //实例
    var contractId = {
        contractId: GetQueryString('contractId')
    };
    var data = [];
    var ContractFlow = [];
    var typeId = '';
    var flowStr = [];
    var productName = [];
    var flowStr1 = [];
    var settlementOf = '';
    var remindUser=[];

    //指定允许上传的文件类型
    var fileObj = {};
    var runId = '';
    var orderRunId = '';

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if (r != null) {
            return unescape(r[2]);
        } else {
            return null;
        }
    }

    function nonEmpty(num) {
        if (num == '' || num == undefined) {
            return ''
        } else {
            return num
        }
    }

    function caseTab(flowStr) {
        for (var i = 0; i < flowStr.length; i++) {
            $('.flowTab').eq(flowStr[i].split("@")[1]).parent().html(flowStr[i].split("@")[0])
        }
        for (var i = 0; i < data.length; i++) {
            var select = 'dd[lay-value=' + data[i].projectId + ']';
            $('.projectType').eq(i).siblings("div .layui-form-select").find('dl').find(select).click()
            var payWay = 'dd[lay-value=' + data[i].payWay + ']';
            $('.payWay').eq(i).siblings("div .layui-form-select").find('dl').find(payWay).click()
            form.render();
        }
    }

    //订单-数据回显
    function ordertab(order){
        table.render({
            elem: '#order'
            ,data:order
            , cols: [[
                {field: 'sort', title: '序号', type: 'numbers'}
                ,{field: 'productId', title: '产品名称', templet: function (d) {
                        if (d.productName!=undefined && d.productName!=''){
                            return '<div class="layui-input-inline productName"  style="display:inline;border-bottom: 1px solid #ccc">' +
                                '   <div name="product'+d.LAY_TABLE_INDEX+'">' +
                                '       <p style="margin-top: 2px" productId="'+d.productId+'" class="spanText">'+
                                d.productName+
                                '           <a onclick="productdel(this,'+d.LAY_TABLE_INDEX+')" class="flowcancelTab" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a>' +
                                '       </p>' +
                                '       <span onclick="productspan(this,'+d.LAY_TABLE_INDEX+')" style="vertical-align: 7px;"><i class="layui-icon layui-icon-add-circle"></i></span>' +
                                '   </div>' +

                                '   <div name="productdiv'+d.LAY_TABLE_INDEX+'" style="display:none;">' +
                                '       <input type="text" style="border-bottom: 1px solid #ccc;width: 150px;padding-bottom:2px" class="search productSea" readonly placeholder="搜索"/>' +
                                '       <span onclick="product('+d.LAY_TABLE_INDEX+')" style="padding: 5px;color: #999;cursor: pointer;margin-left:-26px">' +
                                '           <i class="layui-icon layui-icon-username product"></i>' +
                                '       </span>' +
                                '   </div>' +
                                '</div>';
                        }
                        return '<div class="layui-input-inline productName"  style="display:inline;border-bottom: 1px solid #ccc">' +
                            '   <div name="product'+d.LAY_TABLE_INDEX+'"><p></p></div>' +
                            '   <div name="productdiv'+d.LAY_TABLE_INDEX+'" style="display:block;">' +
                            '       <input type="text" style="border-bottom: 1px solid #ccc;width: 150px;padding-bottom:2px" class="search productSea" readonly placeholder="搜索"/>' +
                            '       <span onclick="product('+d.LAY_TABLE_INDEX+')" style="padding: 5px;color: #999;cursor: pointer;margin-left:-26px">' +
                            '           <i class="layui-icon layui-icon-username product" ></i>' +
                            '       </span>' +
                            '   </div>' +
                            '</div>';
                    }}
                , {field: 'shippingDate', title: '发货时间', event: 'date', data_field: "dBeginDate"}
                , {field: 'number', title: '发货数量', edit: true}
                , {field: 'runId', title: '关联流程',width:300, templet: function (d) {
                        return '<div  id="flowOrder">' +
                            ' <span name="flowTab0"></span>' +
                            ' <div style="display: block;border-bottom: 1px solid #ccc;" class="flowOrder">' +
                            '<input type="text" class="search" readonly placeholder="搜索"/>' +
                            '<span onclick="flowTab(\'order\','+JSON.stringify(d).replace(/"/g, '&quot;')+')" style="padding: 5px;color: #999;cursor: pointer;">' +
                            '<i class="layui-icon layui-icon-search flow-Order" ></i>' +
                            ' </span>' +
                            ' </div>' +
                            ' </div>';
                    }
                }
                , {field: 'remarks', title: '备注', edit: true}
                , {title: '操作', align: 'center', toolbar: '#orderDel'}
            ]]
            , done: function (res, curr, count) {
                var data=res.data;
                for (var k in data) {
                    var flowtab=$('div[lay-id="order"] .layui-table-main tr[data-index="'+data[k].LAY_TABLE_INDEX+'"]');
                    //回显流程
                    var runIds=data[k]['runIds'];
                    var flowName='';
                    for (var r in runIds){
                        flowName += '<p style="display: block; margin-top: 2px" runId='+nonEmpty(runIds[r].runId)+' class="spanText">' + runIds[r].runName +
                            '<a title="取消" onclick="flowtabdel($(this))" class="flowcancelTab" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a>' +
                            '</p>';
                    }
                    $(flowtab).find('td[data-field="runId"] span[name="flowTab0"]').html('');
                    $(flowtab).find('td[data-field="runId"] span[name="flowTab0"]').append(flowName);
                }
            }
            , page: false
        });
    }

    //提醒计划-数据回显
    function plantab(plan){
        table.render({
            elem: '#plan'
            ,data:plan
            , cols: [[
                {field: 'sort', title: '序号', type: 'numbers',}
                , {
                    field: 'userName', title: '提醒对象', templet: function () {
                        return '<div class="username"><input id="governor" type="text" name="parentId" style="border-bottom: 1px solid #ccc;background: white" class="search" readonly placeholder="搜索用户"/>' +
                            '<span style="padding: 5px;color: #999;cursor: pointer;margin-left:-26px"><i class="layui-icon layui-icon-username remind"></i></span>' +
                            '</div></div>'
                    }
                }
                , {field: 'remindDate', title: '提醒日期', event: 'remindDate', data_field: "dBeginDate"}
                , {field: 'content', title: '提醒内容', edit: true}
                , {field: 'remarks', title: '备注', edit: true}
                , {title: '操作', align: 'center', toolbar: '#planDel'}
            ]]
            , page: false
            , done: function (obj) {
                for(var i=0;i<obj.data.length;i++){
                    $('#governor').attr('id', 'governor' + i)
                    $('#governor'+i).val(obj.data[i].userName)
                    $('#governor'+i).attr('username',obj.data[i].userName)
                    $('#governor'+i).attr('user_id',obj.data[i].userId)
                    remindUser.push('governor'+i+'@'+obj.data[i].userId+'@'+obj.data[i].userName)
                }
                //提醒计划-提醒对象
                $('.remind').click(function () {
                    var num = $('.remind').index(this)
                    $(this).parents('.username').children('input').attr('id', 'governor' + num)
                    user_id = 'governor' + num;
                    $.popWindow("/common/selectUser?0");
                });
            }
        });
    }

    //结算情况表格
    function settlementOftab(settlementOf){
        table.render({
            elem: '#settlementOf'
            ,data:settlementOf
            , page: false
            , cols: [[
                {field: 'sort', title: '序号', type: 'numbers',}
                , {
                    field: 'projectType', title: '款项性质', event: 'type', templet: function (d) {
                        var str = '<option value="0">收入</option>\n' +
                            '<option value="1">支出</option>\n'
                        return '<select class="projectType" lay-filter="projectType" lay-verify="required" >\n' + str + '</select>';
                    }
                }
                , {field: 'payType', title: '款项类别', edit: true}
                , {field: 'money', title: '款项金额（元）', edit: true}
                , {field: 'payWay', title: '打款方式', event: 'type', templet: function (d) {
                        // 模板的实现方式也是多种多样，这里简单返回固定的
                        return '<select class="payWay" lay-filter="payWay" lay-verify="required" >\n' +
                            '<option value="01">现金</option>\n' +
                            '<option value="02">转账</option>\n' +
                            '<option value="03">支票</option>\n' +
                            '<option value="04">支付宝</option>\n' +
                            '<option value="05">微信</option>\n' +
                            '<option value="06">其他</option>\n' +
                            '</select>';

                    }
                }
                , {field: 'payAccount', title: '打款账号', edit: true}
                , {field: 'payTime',title: '打款时间', event: 'date', data_field: "dDate"}
                , {field: 'invoiceTime', title: '开票时间', event: 'date', data_field: "dDate"}
                , {field: 'runId', title: '关联流程',width:300, templet: function (d) {
                        return '<div  id="flowTab">' +
                            ' <span name="flowTab0"></span>' +
                            ' <div style="display:block; border-bottom: 1px solid #ccc;" class="flowTab">' +
                            '<input type="text" class="search" readonly placeholder="搜索"/>' +
                            '<span style="padding: 5px;color: #999;cursor: pointer;">' +
                            '<i class="layui-icon layui-icon-search flow-Tab" onclick="flowTab(\'settlementOf\','+JSON.stringify(d).replace(/"/g, '&quot;')+')"></i>' +
                            ' </span>' +
                            ' </div>' +
                            ' </div>';
                    }
                }
                , {field: 'remarks', title: '备注', edit: true}
                , {title: '操作', align: 'center', toolbar: '#settlementOfDel'}
            ]]
            ,done: function (res, curr, count) {
                $('.layui-table-body').height($(window).height() - 230)
                var data=res.data;
                for (var k in data) {
                    //回显  下拉框
                    var flowtab=$('div[lay-id="settlementOf"] .layui-table-main tr[data-index="'+data[k].LAY_TABLE_INDEX+'"]');
                    $(flowtab).find('select[lay-filter="projectType"]').val(data[k].projectTypeId);
                    $(flowtab).find('select[lay-filter="payWay"]').val(data[k].payWayId);

                    //回显流程
                    var runIds=data[k]['runIds'];
                    var flowName='';
                    for (var r in runIds){
                        flowName += '<p style="margin-top: 2px" runId='+nonEmpty(runIds[r].runId)+' class="spanText">' + runIds[r].runName +
                            '<a title="取消" onclick="flowtabdel($(this))" class="flowcancelTab" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a>' +
                            '</p><br/>';
                    }
                    $(flowtab).find('td[data-field="runId"] span[name="flowTab0"]').html('');
                    $(flowtab).find('td[data-field="runId"] span[name="flowTab0"]').append(flowName);
                }

                //结算情况 款项性能下拉框监听事件
                form.on('select(projectType)', function(pr){
                    var dataindex=$(pr.elem).parents('tr').attr("data-index");
                    data[dataindex].projectTypeId=pr.value;
                });

                //结算情况 打款方式 下拉框监听事件
                form.on('select(payWay)', function(pa){
                    var dataindex=$(pa.elem).parents('tr').attr("data-index");
                    data[dataindex].payWayId=pa.value;
                });

                form.render('select');
            }
        });
    }

    //选择流程
    function flowTab(layid,d) {
        var num=d.LAY_TABLE_INDEX;
        var flowtab=$('div[lay-id="'+layid+'"] .layui-table-main tr[data-index="'+num+'"]').find('td[data-field="runId"]').find('span[name="flowTab0"]');
        layer.open({
            type: 1,
            title: ['选择流程'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;line-height: 30px" placeholder="请输入流程的标题"/><i class="layui-icon layui-icon-search flowIcon" style="margin-left: -30px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="flowTable"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                var runIds=[];
                $(flowtab).find('p').each(function(index,element){
                    runIds.push($(element).attr('runid'));
                });

                table.render({
                    elem: '#flowTable'
                    , url: '/workflow/work/selectAll?page=1&pageSize=20&useFlag=true'
                    , page: true
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'runName', title: '流程标题',templet:function (d) {
                                return d.flowRun.runName
                            }}
                        , {field: 'userName', title: '创建人'}
                        , {field: 'createTime', title: '创建时间'}
                    ]]
                    ,done: function (res, curr, count) {
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (runIds.indexOf(String(data[i].runId)) > -1) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED=true;
                            }
                        }
                        form.render();
                    }, parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "data": res.obj //解析数据列表
                        };
                    }
                });


                $('.flowIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if ($('.search') != '') {
                        table.reload('flowTable', {
                            url: '/contract/selectFlowBy',
                            method: 'post',
                            where: {
                                cha: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('flowTable')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                if (data != '') {
                    var flowName = '';
                    for (var i = 0; i < data.length; i++) {
                        flowName += '<p style="display: block; margin-top: 2px" runId='+nonEmpty(data[i].runId)+' class="spanText">' + data[i].flowRun.runName + '<a title="取消" onclick="flowtabdel($(this))" num=' + [i] + ' class="flowcancelTab" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></p>'
                    }
                    $(flowtab).html('');
                    $(flowtab).append(flowName);

                    layer.close(index);
                }
            }
        })
    }

    //结算情况 的关联流程删除
    function flowtabdel(name){
        $(name).parent('.spanText').siblings('br').remove();
        $(name).parent('.spanText').remove();
    }

    //订单-产品名称
    function product(num) {
        var parentid=$('div[name="product'+num+'"] p').attr('productId');

        layer.open({
            type: 1,
            title: ['合同选择'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;height: 30px" placeholder="请输入合同的编号及标题"/><i class="layui-icon layui-icon-search flowIcon" style="margin-left: -30px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="productTable"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                $('.laytable-cell-1-0-1').css("display", "inherit");

                table.render({
                    elem: '#productTable'
                    , url: '/product/selectProduct'
                    , cols: [[
                        {type: 'radio'}
                        , {field: 'productId', title: '产品编号'}
                        , {field: 'productName', title: '产品名称'}
                        , {field: 'meteringUnit', title: '产品单位 '}
                    ]]
                    , page: true
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "data": res.obj //解析数据列表
                        };
                    }
                    ,done: function (res, curr, count) {
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (String(data[i].productId)===parentid) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="productTable"] tr[data-index="' + index + '"] input[type="radio"]').prop('checked', true);
                                $('div[lay-id="productTable"] tr[data-index="' + index + '"] input[type="radio"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED=true;
                            }
                        }
                        form.render();
                    }
                });

                $('.flowIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if (search != '') {
                        table.reload('productTable', {
                            url: '/product/selectByConditionProduct',
                            method: 'post',
                            where: {
                                productName: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('productTable')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                if (data != '') {
                    var d=data[0];
                    var str = '<p style="margin-top: 2px" productId="'+d.productId+'" class="spanText">'+ d.productName +
                        '   <a onclick="productdel(this,'+num+')" class="flowcancelTab" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a>' +
                        '</p>'+
                        '<span onclick="productspan(this,'+num+')" style="vertical-align: 7px;"><i class="layui-icon layui-icon-add-circle"></i></span>';

                    $('div[name="product'+num+'"]').html('');
                    $('div[name="product'+num+'"]').append(str);
                    $('div[name="productdiv'+num+'"]').css('display','none');
                    layer.close(index)
                }
            }
        })
    }

    //订单 产品名称删除
    function productdel(item,num){
        $('div[name="product'+num+'"]').html('');
        $('div[name="productdiv'+num+'"]').css('display','block');
    }

    //订单显示选择产品
    function productspan(item,num){
        var productdiv=$('div[name="productdiv'+num+'"]').css('display');
        if(productdiv==='block'){
            $('div[name="productdiv'+num+'"]').css('display','none');
        }else{
            $('div[name="productdiv'+num+'"]').css('display','block');
        }
    }


    //监听金额大小写
    $('[name="money"]').on("change", function () {
        var money = $('[name="money"]').val();
        var fraction = ['角', '分'];
        var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
        var unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']];
        var head = money < 0 ? '欠' : '';
        money = Math.abs(money);
        var s = '';
        for (var i = 0; i < fraction.length; i++) {
            s += (digit[Math.floor(money * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
        }
        s = s || '整';
        money = Math.floor(money);
        for (var i = 0; i < unit[0].length && money > 0; i++) {
            var p = '';
            for (var j = 0; j < unit[1].length && money > 0; j++) {
                p = digit[money % 10] + unit[1][j] + p;
                money = Math.floor(money / 10);
            }
            s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
        }
        var sum = head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
        $('[name="moneyCp"]').val(sum);
    })

    //判断-基本信息合同编号是否重复
    $('[name="contractNo"]').change(function () {
        $.ajax({
            url: '/contract/selectContractByNo',
            type: 'get',
            dataType: 'json',
            data: {
                contractNo: $('[name="contractNo"]').val()
            },
            success: function (data) {
                if (data.msg != "该合同编号可以使用") {
                    layer.msg('合同编号重复', {icon: 2})
                }
            }
        })
    })

    $('.return').click(function () {
        history.go(-1)
    })

    //订单-关联流程
    $('.flow-Order').click(function () {
        var num = $('.flow-Order').index(this)
        $(this).parents('#flowOrder').attr('id', 'flowOrder' + num)
        layer.open({
            type: 1,
            title: ['选择流程'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;line-height: 30px" placeholder="请输入流程的标题"/><i class="layui-icon layui-icon-search flowIcon" style="margin-left: -30px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="orderTable"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                table.render({
                    elem: '#orderTable'
                    , url: '/workflow/work/selectAll?page=1&pageSize=20&useFlag=true'
                    , page: true
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'runName', title: '流程标题',templet:function (d) {
                                return d.flowRun.runName
                            }}
                        , {field: 'userName', title: '创建人'}
                        , {field: 'createTime', title: '创建时间'}
                    ]]
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "data": res.obj //解析数据列表
                        };
                    }
                    ,done: function (res, curr, count) {
                        $("[data-field='id']").css('display', 'none');
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (runIds.indexOf(String(data[i].runId)) > -1) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED=true;
                            }
                        }
                        form.render();
                    }
                });
                $('.flowIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if (search != '') {
                        table.reload('orderTable', {
                            url: '/contract/selectFlowBy',
                            method: 'post',
                            where: {
                                cha: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('orderTable')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                if (data != '') {

                    var flowName = ''
                    var flowOrder = '#flowOrder' + num
                    for (var i = 0; i < data.length; i++) {
                        $('#flowOrder' + num).children('span').html('');
                        flowName += '<p style="margin-top: 0" runId=' + nonEmpty(data[i].runId) + ' class="spanText flowSpan">' + data[i].flowRun.runName + '<a title="取消" num=' + [i] + ' class="flowcancelOrder" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></span><br>'
                    }
                    $('#flowOrder' + num).children('span').append(flowName)
                    $(document).on('click', '.flowcancelOrder', function () {
                        $(this).parent('.spanText').prev().remove()
                        $(this).parent('.spanText').prev().next().remove()
                        flowStr1.push($('#flowOrder' + num).html() + "@" + num)
                    });
                    flowStr1.push($('#flowOrder' + num).html() + "@" + num)

                    var dataIndex = $('#flowOrder' + num).parents('tr').attr("data-index");
                    var field = $('#flowOrder' + num).parents('td').attr('data-field');
                    var runId = ''
                    for (var i = 0; i < $('#flowOrder' + num).find('.flowSpan').length; i++) {
                        runId += $('#flowOrder' + num).find('.flowSpan').eq(i).attr('runid') + ','
                    }
                    table.cache["order"][dataIndex][field] = runId
                    layer.close(index)
                }
            }
        })
    })

    //    结算情况    添加按钮点击事件
    $("#addButton").click(function () {
        var data = table.cache["settlementOf"];
        for(var d in data){
            var flowtab=$('div[lay-id="settlementOf"] .layui-table-main tr[data-index="'+data[d].LAY_TABLE_INDEX+'"]');
            var runs=[];
            $(flowtab).find('td[data-field="runId"] span[name="flowTab0"] p').each(function(index,element){
                var name=$(element).text();
                var rname=name.substring(0,name.length-1);
                var obj={
                    runId : $(element).attr('runid')
                    ,runName :rname
                }
                runs.push(obj);
            });
            data[d].runIds=runs;
        }
        var data1 = {
            conProjectId:''
            ,contractId: ''
            ,invoiceTime: ""
            ,invoiceTimeStr: ""
            ,money: ''
            ,payAccount: ""
            ,payTime: ""
            ,payTimeStr: ""
            ,payType: ""
            ,payWay: ""
            ,payWayId: ""
            ,projectType: ""
            ,projectTypeId: ''
            ,remarks: ""
            ,runId: ""
            ,runIds: []
            ,title: ""
        };
        data.push(data1);
        table.reload('settlementOf', {
            data: data
        });
    });

    //订单 添加按钮点击事件
    $("#orderButton").click(function () {
        var data = table.cache["order"];
        for(var d in data){
            var flowtab=$('div[lay-id="order"] .layui-table-main tr[data-index="'+data[d].LAY_TABLE_INDEX+'"]');

            //关联流程
            var runs=[];
            $(flowtab).find('td[data-field="runId"] span[name="flowTab0"] p').each(function(index,element){
                var name=$(element).text();
                var rname=name.substring(0,name.length-1);
                var obj={
                    runId : $(element).attr('runid')
                    ,runName :rname
                }
                runs.push(obj);
            });
            data[d].runIds=runs;

            //产品名称
            var prname=$(flowtab).find('td[data-field="productId"] div[name="product'+data[d].LAY_TABLE_INDEX+'"] p');
            data[d].productId=$(prname).attr('productid');

            var name1=$(prname).text();
            var name2=name1.replace(/\s+/g,"");
            var rname1=name2.substring(0,name2.length-1);
            data[d].productName=rname1;

        }
        var data1 = {
            contractId: '',
            contractName: "",
            number: "",
            productId: '',
            remarks: "",
            runId: "",
            runIds:[],
            shippingDate: "",
            transportId: '',
        };
        data.push(data1);
        table.reload('order', {
            data: data
        });
    });

    //提醒计划  添加按钮点击事件
    $("#planButton").click(function () {
        var data = table.cache["plan"];
        for(var d in data) {
            var flowtab = $('div[lay-id="plan"] .layui-table-main tr[data-index="' + data[d].LAY_TABLE_INDEX + '"]');
            var input=$(flowtab).find('td[data-field="userName"] input[id="governor'+data[d].LAY_TABLE_INDEX+'"]');
            data[d].userName=$(input).attr('username');
            data[d].userId=$(input).attr('user_id');

        }
        var data1 = {
            content: ""
            ,contractId: ''
            ,remarks: ""
            ,remindDate: ""
            ,remindFlag: ''
            ,remindId: ''
            ,userId: ""
            ,userName: ""
        };
        data.push(data1);
        table.reload('plan', {
            data: data
        });
    });

    //选择流程
    $(document).on('click', '.flowAet', function() {
        var runIds = [];
        $('.flowSpanRun').each(function (index, element) {
            runIds.push($(element).attr('runid'));
        });
        layer.open({
            type: 1,
            title: ['选择流程'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;line-height: 30px" placeholder="请输入流程的标题"/><i class="layui-icon layui-icon-search flowIcon" style="margin-left: -30px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="flowTable"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                table.render({
                    elem: '#flowTable'
                    , url: '/workflow/work/selectAll?page=1&pageSize=20&useFlag=true'
                    , page: true
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'runName', title: '流程标题',templet:function (d) {
                                return d.flowRun.runName
                            }}
                        , {field: 'userName', title: '创建人'}
                        , {field: 'createTime', title: '创建时间'}
                    ]]
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "data": res.obj //解析数据列表
                        };
                    }
                    , done: function (res, curr, count) {
                        $("[data-field='id']").css('display', 'none');
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (runIds.indexOf(String(data[i].runId)) > -1) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                                $('div[lay-id="flowTable"] tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED = true;
                            }
                        }
                        form.render();
                    }
                });
                $('.flowIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if (search != '') {
                        table.reload('flowTable', {
                            url: '/contract/selectFlowBy',
                            method: 'post',
                            where: {
                                cha: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('flowTable')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                var flowName = '';
                var runId = ''
                for (var i = 0; i < $('.flowSpanRun').length; i++) {
                    runId += $('.flowSpanRun').eq(i).attr('runId') + ','
                }
                var num = {}
                for (var i = 0; i < data.length; i++) {
                    flowName += '<p class="spanText flowSpan flowSpanRun" runId="' + data[i].runId + '">' +
                        data[i].flowRun.runName + '<a title="取消" num=' + [i] + ' onclick="cancelzidel(this)" class="flowcancel" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></p>'
                }
                $('#flow span:eq(0)').html('');
                $('#flow span:eq(0)').append(flowName);
                layer.close(index)
            }
        })
    })

    //选择子合同
    $(document).on('click', '.localAet', function() {
        var runIds = [];
        var contractId = '';
        for (var i = 0; i < $('.contract').length; i++) {
            runIds.push($('.contract').eq(i).attr('contractId'));
            contractId+=$('.contract').eq(i).attr('contractId')+','
        }
        layer.open({
            type: 1,
            title: ['合同选择'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;line-height: 30px" type="text" placeholder="请输入合同编号或标题"/><i class="layui-icon layui-icon-search subIcon" style="margin-left: -45px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="subcontract"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                table.render({
                    elem: '#subcontract'
                    , url: '/contract/selectContractZi'
                    , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'contractNo', title: '合同编号'}
                        , {field: 'title', title: '合同标题'}
                        , {field: 'aSignTime', title: '创建时间'}
                    ]]
                    , page: true
                    , done: function (res, curr, count) {
                        $("[data-field='id']").css('display', 'none');
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (runIds.indexOf(String(data[i].contractId)) > -1) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="subcontract"] tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                                $('div[lay-id="subcontract"] tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED = true;
                            }
                        }
                        form.render();
                    }
                });
                $('.subIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if (search = '') {
                        table.reload('subcontract', {
                            url: '/contract/selectContractZiBy',
                            method: 'post',
                            where: {
                                cha: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('subcontract')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    str += '<p class="spanText flowSpan contract" contractId="' + data[i].contractId + '">' +
                        data[i].title + '<a title="取消" num=' + [i] + ' class="flowcancel" onclick="cancelzidel(this)" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></p>'
                }
                $('#local span:eq(0)').html('');
                $('#local span:eq(0)').append(str);
                layer.close(index)
            }
        })
    })

    $('.cancel').click(function () {
        $(this).parents('.spanText').remove();
        $('.add-item').remove();
        if ($(this).siblings('.spanText').length == 0) {
            $('.parent').show();
            $('.parent').siblings().last().show();
        }
    });

    //主合同
    $('.master').click(function () {
        layer.open({
            type: 1,
            title: ['合同选择'],
            area: ['750px', '640px'],
            shadeClose: true, //点击遮罩关闭
            content: '<div>' +
                '<input style="width: 200px;margin:20px 0 0 20px;padding-left: 10px;height: 30px" placeholder="请输入合同的编号及标题"/><i class="layui-icon layui-icon-search flowIcon" style="margin-left: -30px"></i></div>' +
                '<div style="margin:0 20px 0 20px;">' +
                '<table class="layui-hide" id="flowTable"></table>' +
                '</div>',
            btn: ['确定']
            , success: function (data) {
                var parentid=$('div[name="Mastercontract"] p').attr('parentid');
                table.render({
                    elem: '#flowTable'
                    , url: '/contract/selectContractAll'
                    , cellMinWidth: 80
                    , cols: [[
                        {type: 'radio', fixed: 'left'}
                        , {field: 'contractNo', title: '合同编号'}
                        , {field: 'title', title: '合同标题'}
                        , {field: 'aSignTime', title: '创建时间'}
                    ]]
                    , page: false
                    ,done: function (res, curr, count) {
                        $("[data-field='id']").css('display', 'none');
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            if (String(data[i].contractId)===parentid) {
                                var index = data[i]['LAY_TABLE_INDEX'];
                                $('div[lay-id="flowTable"] tr[data-index="' + index + '"] input[type="radio"]').prop('checked', true);
                                $('div[lay-id="flowTable"] tr[data-index="' + index + '"] input[type="radio"]').next().addClass('layui-form-checked');
                                data[i].LAY_CHECKED=true;
                            }
                        }
                        form.render();
                    }
                });

                //搜索点击事件
                $('.flowIcon').click(function () {
                    var search = $(this).siblings('input').val()
                    if (search != '') {
                        table.reload('flowTable', {
                            url: '/contract/selectContractBy',
                            method: 'get',
                            where: {
                                cha: search
                            }
                        })
                    }
                });
            },
            yes: function (index) {
                var checkStatus = table.checkStatus('flowTable')  // 打开页面中的table ID
                    , data = checkStatus.data;     //  这个data一直为 []
                if (data != '') {
                    var str = '';
                    for (var i = 0; i < data.length; i++) {
                        str = '<p class="spanText parentid" parentid="' + data[i].contractId + '" style="margin-top:5px;position:relative">' + data[i].title + '<a style="color: darkgrey;cursor:pointer;margin-left: 5px;" title="取消" class="cancel"  onclick="cancel(this)">×</a></p>' +
                            '<span class="add-item" style="vertical-align: 7px;" onclick="additem(this)"><i class="layui-icon layui-icon-add-circle"></i></span>'
                    }
                    $('div[name="Mastercontract"] p').remove();
                    $('.add-item').remove();
                    $('div[name="Mastercontract"]').prepend(str);
                    $('.parent').hide();
                    $('.parent').siblings().last().hide();
                    layer.close(index)
                }
            }
        })
    });

    $('#file').click(function () {
        window.location = "../../download?" + $(this).attr('deurl');
    });

    $('.close').click(function () {
        $(this).parents('.fileDiv').remove();
    })

    //主合同添加
    function additem(itme) {
        $('.parent').show();
        $('.parent').siblings().last().show();
    };

    //主合同删除
    function cancel(itme) {
        $(itme).parents('.spanText').remove();
        $('.add-item').remove();
        if ($(this).siblings('.spanText').length == 0) {
            $('.parent').show();
            $('.parent').siblings().last().show();
        }
    };

    //子合同删除
    function cancelzidel(itme){
        $(itme).parents('.spanText').remove();
    };

    //初始化
    $(function () {
        $.ajax({
            url: '/portals/selPortalsUser',
            type: 'get',
            dataType: 'json',
            data: data,
            success: function (data) {
                $('#userId').html('<span class="spanText" userId=' + data.object.userId + ' style="margin-top:7px" >' + data.object.userName + '</span>')
            }
        });

        //类型
        $.ajax({
            url: '/contract/selectTypeAll',
            type: 'get',
            dataType: 'json',
            success: function (data) {
                var str = '<option></option>';
                for (var i = 0; i < data.data.length; i++) {
                    str += '<option value="' + data.data[i].typeId + '">' + data.data[i].typeName + '</option>'
                }
                $('#contractType').append(str);
                $('.layui-unselect .layui-form-select .layui-form-selected').css("overflow", "visible")
            }
        });
    });

    layui.use(['element','form', 'layedit', 'laydate', 'table', 'upload'], function () {
        form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , layedit = layui.layedit
            , table = layui.table
            , upload = layui.upload
            , element = layui.element;

        //建立编辑器
        var indexs = layedit.build('texPart');
        //保存
        $('.save').click(function () {
            var data = table.cache["order"];
            for(var d in data) {
                var str = ''
                var flowtab = $('div[lay-id="order"] .layui-table-main tr[data-index="' + data[d].LAY_TABLE_INDEX + '"]');

                //关联流程
                var runs = [];
                $(flowtab).find('td[data-field="runId"] span[name="flowTab0"] p').each(function (index, element) {
                    var name = $(element).text();
                    var rname = name.substring(0, name.length - 1);
                    var obj = {
                        runId: $(element).attr('runid')
                        , runName: rname
                    }
                    str += $(element).attr('runid')+','
                    runs.push(obj);

                });
                data[d].runIds = runs;

                //产品名称
                var prname = $(flowtab).find('td[data-field="productId"] div[name="product' + data[d].LAY_TABLE_INDEX + '"] p');
                data[d].productId = $(prname).attr('productid');

                var name1 = $(prname).text();
                var name2 = name1.replace(/\s+/g, "");
                var rname1 = name2.substring(0, name2.length - 1);
                data[d].productName = rname1;
                data[d].runId =str;
            }
            var flowSpanId = ''
            for (var i = 0; i < $('#local .flowSpan').length; i++) {
                flowSpanId += $('.flowSpan').eq(i).attr('contractId') + ','
            }
            //合同基本信息
            var obj = {};
            obj.contractId = GetQueryString('contractId');
            var ajaxforms = $('#ajaxforms').serializeArray();
            $.each(ajaxforms, function (i, v) {
                obj[v.name] = v.value;
            });
            obj.contractNo = $('.contractNo').val()
            obj.dept_id = $('#rescueUser').attr('deptid')
            var urlId='';
            var urlName='';
            for(var i=0;i<$('.file').length;i++){
                urlId+=$('.file').eq(i).attr('aid') + '@' + $('.file').eq(i).attr('ym') + '_' + $('.file').eq(i).attr('attachId') + ',';
                urlName+=$('.file').eq(i).attr('name')+ '*';
            }
            obj.moneyCp = $('[name="moneyCp"]').val();
            obj.attachmentId = urlId;
            obj.attachmentName = urlName;
            obj.content = layedit.getText(indexs);
            obj.userId = $('#userId').children().attr('userId');
            obj.subContract = flowSpanId;
            obj.parentId = $('.parentid').attr('parentid');
            obj.typeId = function () {
                if(typeId==''){
                    return $('#contractType').val()
                }else{
                    return typeId
                }
            }();

            //合同项目
            var ContractProject = table.cache["settlementOf"];
            if (runId != '' && runId != undefined) {
                ContractProject[0]["runId"] = runId;
            }
            var data = table.cache["settlementOf"];
            for(var d in data){
                var str = ''
                var flowtab=$('div[lay-id="settlementOf"] .layui-table-main tr[data-index="'+data[d].LAY_TABLE_INDEX+'"]');
                var runs=[];
                $(flowtab).find('td[data-field="runId"] span[name="flowTab0"] p').each(function(index,element){
                    var name=$(element).text();
                    var rname=name.substring(0,name.length-1);
                    var obj={
                        runId : $(element).attr('runid')
                        ,runName :rname
                    }
                    str += $(element).attr('runid')+','
                    runs.push(obj);
                });
                data[d].runIds=runs;
                data[d].runId=str;
            }
            for(var i=0;i<ContractProject.length;i++){
                ContractProject[i]["payWay"] = ContractProject[i].payWayId;
                ContractProject[i]["projectType"] = ContractProject[i].projectTypeId;
            }


            var ContractTransport = table.cache["order"];


            if (orderRunId != '' && orderRunId != undefined) {
                ContractTransport[0]["runId"] = orderRunId;
            }

            var data = table.cache["plan"];
            for(var d in data) {
                var flowtab = $('div[lay-id="plan"] .layui-table-main tr[data-index="' + data[d].LAY_TABLE_INDEX + '"]');
                var input=$(flowtab).find('td[data-field="userName"] input[id="governor'+data[d].LAY_TABLE_INDEX+'"]');
                data[d].userName=$(input).attr('username');
                data[d].userId=$(input).attr('user_id');
                console.log($(input).attr('user_id'))
            }
            //流程
            ContractFlow.length = 0;
            $('.flowSpanRun').each(function (index, element) {
                ContractFlow.push({runId: $(element).attr('runid'), runName: $(element).text().split('×')[0]})
            });
            for (var i = 0; i < $('.required').length; i++) {
                if ($('.required').eq(i).val() == '') {
                    var content=$('.required').eq(i).parents('.layui-inline').children('.layui-form-label').text()
                    if(content==''){
                        var content=$('.required').eq(i).parents('.layui-form-item').children('.layui-form-label').text()
                    }
                    $.layerMsg({
                        content: '' + content + '不能为空',
                        icon: 2
                    });
                    return false;
                }
            }

            var data = {
                ContractProject: ContractProject,
                ContractTransport: ContractTransport,
                ContractRemind: table.cache["plan"],
                ContractFlow: ContractFlow,
                Contract: obj
            };
//
//            console.log(data);
//            return false;
            $.ajax({
                url: '/contract/upContracts',
                type: 'post',
                dataType: 'json',
                contentType: "application/json",
                data: JSON.stringify(data),
                success: function (data) {
                    if (data.flag) {
                        layer.msg('保存成功！', {icon: 6});
                        history.go(-1)
                    }
                },
                error: function (data) {
                    layer.msg('保存失败！', {icon: 2});
                }
            })
        });

        //编辑合同-回显基本信息数据
        $.ajax({
            url: '/contract/selectContracts',
            type: 'get',
            dataType: 'json',
            data: contractId,
            success: function (res) {

                //基本信息
                var data = res.obj[0].object;
                var data1 = res.obj[1].obj; //相关流程
                var data2 = res.obj[2].object; //订单
                var data3 = res.obj[3].object; //提醒计划
                var data4 = res.obj[4].object; //结算情况

                var select = 'dd[lay-value=' + data.typeId + ']';

                //基本信息回显
                $('[name="contractNo"]').val(data.contractNo)
                $('[name="title"]').val(data.title)
                $('[name="targetName"]').val(data.targetName)
                $('[name="money"]').val(data.money)
                $('[name="moneyCp"]').val(data.moneyCp)
                $('[name="aUser"]').val(data.aUser)
                $('[name="bUser"]').val(data.bUser)
                $('[name="aAddress"]').val(data.aAddress)
                $('[name="bAddress"]').val(data.bAddress)
                $('[name="aLinkman"]').val(data.aLinkman)
                $('[name="bLinkman"]').val(data.bLinkman)
                $('[name="aPhone"]').val(data.aPhone)
                $('[name="bPhone"]').val(data.bPhone)
                $('[name="aSign"]').val(data.aSign)
                $('[name="bSign"]').val(data.bSign)
                $('[name="aSignTime"]').val(data.aSignTime)
                $('[name="bSignTime"]').val(data.bSignTime)
                $('[name="remarks"]').val(data.remarks)
                $('[name="authorized_representative"]').val(data.authorized_representative)
                $('[name="do_address"]').val(data.do_address)
                $('[name="date_comment"]').val(data.date_comment)
                $('[name="duration_startdate"]').val(data.duration_startdate)
                $('[name="duration_enddate"]').val(data.duration_enddate)
                //所属部门
                $('#rescueUser').val(data.deptName)
                $("#rescueUser").attr('dept_id',data.dept_id);
                //类型
                $('#contractType').val(data.typeId);
                //对方单
                $('input[name=othersideunit][value="1"]').attr("checked", data.othersideUnit == "1" ? true : false);
                $('input[name=othersideunit][value="2"]').attr("checked", data.othersideUnit == "2" ? true : false);
                // 风险评估
                $('input[name=risk_assessment][value="0"]').attr("checked", data.risk_assessment == 0 ? true : false);
                $('input[name=risk_assessment][value="1"]').attr("checked", data.risk_assessment == 1 ? true : false);
                // 合同评审
                $('input[name=contract_approval][value="0"]').attr("checked", data.contract_approval == 0 ? true : false);
                $('input[name=contract_approval][value="1"]').attr("checked", data.contract_approval == 1 ? true : false);
                $('#contract_type').val(data.contract_type);
                $('#executive_unit').val(data.executive_unit);
                form.render();
                $('#userId').html('<span class="spanText" userId=' + data.userId + ' style="margin-top:7px">' + data.userName + '</span>'); //跟进人

                //主合同
                if (data.parentName != undefined && data.parentName != '') {
                    var str = '<p class="spanText parentid" parentid="' + data.parentId + '" style="margin-top:5px;position:relative">' + data.parentName + '<a style="color: darkgrey;cursor:pointer;margin-left: 5px;" title="取消" class="cancel" onclick="cancel(this)">×</a></p>' +
                        '<span class="add-item" style="vertical-align: 7px;" onclick="additem(this)"><i class="layui-icon layui-icon-add-circle"></i></span>'
                    $('div[name="Mastercontract"]').prepend(str);
                    $('.parent').hide();
                    $('.parent').siblings().last().hide();
                }

                //子合同
                if (data.subContracts != undefined && data.subContracts != '') {
                    var str='';
                    for(var i=0;i<data.subContracts.length;i++){
                        str+='<p class="spanText flowSpan  contract" contractId="' + data.subContracts[i].contractId + '">'+
                            data.subContracts[i].title+
                            '<a title="取消" num="'+i+'" class="flowcancel" onclick="cancelzidel(this)" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></p>'
                    }
                    $('#local span:eq(0)').html(str);
                }

                //相关流程
                if (data1 != undefined && data1 != '') {
                    var str=''
                    for(var i=0;i<data1.length;i++){
                        str+='<p class="spanText flowSpan  flowSpanRun" runId="' + data1[i].runId + '">'+
                            data1[i].runName+
                            '<a title="取消" num="'+i+'" class="flowcancel" onclick="cancelzidel(this)" style="cursor: pointer;color: darkgrey;padding-left:10px">×</a></p>'
                    }
                    $('#flow span:eq(0)').html(str);
                }

                //结算情况表格
                settlementOftab(data4);

                //订单-数据回显
                ordertab(data2);

                //提醒计划-数据回显
                plantab(data3);

                //附件
                var fileStr = '';
                if (data.attachment != undefined && data.attachment != '') {
                    for (var i = 0; i < data.attachment.length; i++) {
                        fileStr += '<div url='+data.attachment[i].attUrl+' style="display:inline-block; margin-right:25px; " class="fileDiv"><div class="relative">' +
                            '   <i class="layui-icon layui-icon-close close"  style="float: right;"></i>' +
                            '  <i class="layui-icon layui-icon-list file" id="file" attachId="' + data.attachment[i].attachId + '"  deurl="' + data.attachment[i].attUrl + '" ym="'+data.attachment[i].ym+'" aid="'+data.attachment[i].aid+'" name="' + data.attachment[i].attachName + '"  style="font-size: 30px;font-size: 100px; padding-left: 20px;line-height: 140px;"></i>' +
                            '  </div>' +
                            '  <div style="margin:10px;" class="fileName">' + data.attachment[i].attachName + '(' + data.attachment[i].size + ')' + '</div></div>';
                    }
                }
                $('.content').last().append(fileStr);
                $('#test3').parent().siblings('div').show();
                //附件下载事件
                $('.fileDiv').click(function () {
                    window.location ='/download?'+$(this).attr('url')
                })

                //合同正文回显
                layedit.setContent(indexs, data.content);
                form.render();
            }
        });

        form.on('select(warehouse)', function (data) {
            typeId = $('#contractType').val()  //获取下拉框的value值
        });

        //第一个表格的工具事件
        table.on('tool(settlementOf)', function (obj) {
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr;
            var data = obj.data;
            var newdata = {};
            if (layEvent === 'date') {
                var field = $(this).data('field');
                var index = tr.attr("data-index");
                laydate.render({
                    elem: this.firstChild
                    , show: true //直接显示
                    , closeStop: this
                    , type: 'datetime'
                    , done: function (value, date) {
                        table.cache["settlementOf"][index][field] = value
                    }
                });
            }
            if (layEvent == 'payWay') {
                var index = tr.attr("data-index");
                var field = $(this).data('field');
                form.on('select(payWay)', function (data) {
                    table.cache["settlementOf"][index][field] = data.value
                });
            }
            if (layEvent == 'projectType') {
                var index = tr.attr("data-index");
                var field = $(this).data('field');
                form.on('select(projectType)', function (data) {
                    table.cache["settlementOf"][index][field] = data.value
                });
            }
            if (layEvent == 'del2') {
                var index = tr.attr("data-index");
                obj.del(tr);
                data = table.cache["settlementOf"];
                data.splice(parseInt(index), 1);
                table.reload('settlementOf', {
                    data: data
                });
                caseTab(flowStr)
                var trs = $("#addTableDiv").find(".layui-table-body").find("tr");
            }

        });

        //订单-工具事件
        table.on('tool(order)', function (obj) {
            var layEvent = obj.event; //获得 lay-event 对应的值
            var datatr = obj.data;//获取行数据
            var tr = obj.tr;
            var me = $(this);
            var newdata = {};
            var data = obj.data;
            if (obj.event === 'date') {
                var field = $(this).data('field');
                var index = tr.attr("data-index");
                laydate.render({
                    elem: this.firstChild
                    , show: true //直接显示
                    , closeStop: this
                    , done: function (value, date) {
                        table.cache["order"][index][field] = value
                    }
                });
            }
            if (layEvent == 'del2') {
                var index = tr.attr("data-index");
                obj.del(tr);
                data = table.cache["order"];
                data.splice(parseInt(index), 1);
                table.reload('order', {
                    data: data
                });
                var trs = $("#orderTableDiv").find(".layui-table-body").find("tr");
            }

        });

        //提醒计划-工具事件
        table.on('tool(plan)', function (obj) {
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr;
            var newdata = {};
            var data = obj.data;
            if (layEvent == 'remindDate') {
                var field = $(this).data('field');
                var index = tr.attr("data-index");
                laydate.render({
                    elem: this.firstChild
                    , show: true //直接显示
                    , closeStop: this
                    , done: function (value, date) {
                        table.cache["plan"][index][field] = value
                    }
                });
            }
            if (layEvent == 'del2') {
                var index = tr.attr("data-index");
                obj.del(tr);
                data = table.cache["plan"];
                data.splice(parseInt(index), 1);
                table.reload('plan', {
                    data: data
                });
                var trs = $("#planTableDiv").find(".layui-table-body").find("tr");
                for (var i = 0; i < remindUser.length; i++) {
                    if (remindUser[i].split("@")[0] != 'governor') {
                        $('#governor').eq(remindUser[i].split("@")[0]).val(remindUser[i].split("@")[2])
                        $('#governor').eq(remindUser[i].split("@")[0]).attr('username', remindUser[i].split("@")[2])
                        $('#governor').eq(remindUser[i].split("@")[0]).attr('user_id', remindUser[i].split("@")[1])
                    }
                }
            }
        });
        upload.render({
            elem: '#test3'
            , url: '../upload?module=contract'
            , multiple: true
            , accept: 'file' //普通文件
            , done: function (res) {
                var str = '';
                if (res.flag) {
                    str += '<div style="display:inline-block;margin-right: 25px" class="fileDiv"><div class="relative">' +
                        '   <i class="layui-icon layui-icon-close close"  style="float: right;"></i>' +
                        '  <i class="layui-icon layui-icon-list file" id="file" aid="'+res.obj[0].aid+'"  ym="'+res.obj[0].ym+'" attachId="'+res.obj[0].attachId+'" deurl="' + res.obj[0].attUrl + '" name="' + res.obj[0].attachName + '"  style="font-size: 30px;font-size: 100px; padding-left: 20px;line-height: 140px;"></i>' +
                        '  </div>' +
                        '  <div style="margin:10px;" class="fileName">' + res.obj[0].attachName + '(' + res.obj[0].fileSize + ')' + '</div></div>';
                    $('.content').last().append(str);
//                    $('.num').html('<i class="layui-icon layui-icon-link" style="margin-right:6px"></i>'+$('.fileName').length+'个附件')
                    $('#test3').parent().siblings('div').show();
                    $('#file').click(function () {
                        window.location = "../../download?" + res.obj[0].attUrl;
                    });
                    $('.close').click(function () {
                        $(this).parents('.fileDiv').remove();
                    })
                }
            }
        });

        //日期
        laydate.render({
            elem: '#aSignTime'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#invoiceTime'
        });
        laydate.render({
            elem: '#bSignTime'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#authorization'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#begins'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#endtime'
            , type: 'datetime'
        });
        //进货人点击添加的按钮
        $(".addExecute").on("click",function(){
            dept_id = 'rescueUser';
            $.popWindow("/common/selectDept?0");
        });

        $('.clearExecute').click(function () {
            $('#rescueUser').attr('dept_id','');
            $('#rescueUser').attr('deptid','');
            $('#rescueUser').val('');
        });
        //合同种类
        $.ajax({
            url:'/code/getCode',
            type: 'get',
            dataType: 'json',
            data:{
                parentNo:'CONTRACT_TYPE'
            },
            success:function (res) {
                var str = '<option></option>';
                for (var i = 0; i <res.obj.length; i++) {
                    str += '<option value="' + res.obj[i].codeNo + '">' + res.obj[i].codeName + '</option>'
                }
                $('#contract_type').append(str);
                form.render('select');
            }
        })
        //执行单位
        $.ajax({
            url:'/code/getCode',
            type: 'get',
            dataType: 'json',
            data:{
                parentNo:'CONTRACT_UNIT'
            },
            success:function (res) {
                var str = '<option></option>';
                for (var i = 0; i <res.obj.length; i++) {
                    str += '<option value="' + res.obj[i].codeNo + '">' + res.obj[i].codeName + '</option>'
                }
                $('#executive_unit').append(str);
                form.render('select');
            }
        })
        // //选择编号按钮点击事件
        // $('button[name="contractNo"]').click(function(){
        //     layer.open({
        //         type: 2,
        //         closeBtn: 2,
        //         btnAlign: 'c',
        //         area: ['50%', '70%'],
        //         content: '/ContractNoView/ContractNumber?display=none',
        //         btn:['确定','取号','重新编号'],
        //         yes: function(index, layero){
        //             $("#layui-layer-iframe"+index)[0].contentWindow.queding();
        //             layer.closeAll();
        //             return false;
        //
        //         },
        //         btn2: function(index, layero){
        //             $("#layui-layer-iframe"+index).contents().find('button[layer1="qunding"]').click();
        //             return false;
        //         },
        //         btn3: function(index, layero){
        //             $("#layui-layer-iframe"+index).contents().find('button[layer2="qunding"]').click();
        //             return false;
        //         }
        //     });
        // });
        //
        // //已取号的点击事件
        // $('.newNum').click(function(){
        //     layer.open({
        //         type: 1,
        //         title: '已取号',
        //         area: ['750px', '640px'],
        //         content:'<div style="margin: 10px"><table id="newNumber" lay-filter="newNumber"></table></div>',
        //         btn: ['确定','返回'],
        //         success:function (res) {
        //             table.render({
        //                 elem: '#newNumber'
        //                 , url: '/ContractNo/findContractNo',
        //                 where:{
        //                     userId:'admin'
        //                 }
        //                 ,cols: [[
        //                     {type: 'numbers', title: '序号',align: 'center', width: 200}
        //                     ,{field: 'contractNo', title: '合同编号', align: 'center'}
        //                 ]]
        //                 ,parseData: function(res){ //res 即为原始返回的数据
        //                     return {
        //                         "code": 0, //解析接口状态
        //                         "msg": res.msg, //解析提示文本
        //                         "count": res.totleNum, //解析数据长度
        //                         "data": res.obj //解析数据列表
        //
        //                     };
        //                 }
        //                 , page:true
        //             });
        //
        //             //监听行单击事件
        //             table.on('row(newNumber)', function (obj) {
        //                 var data=obj.data
        //                 conNumber = data.contractNo
        //                 $(this).addClass('bg').siblings().removeClass('bg')
        //             });
        //         },
        //         yes: function (index) {
        //             $('.contractNo').val(conNumber)
        //             layer.closeAll();
        //         }
        //     })
        // })
    })

</script>

</html>
